import { http, httpPut, httpGet } from '../http'

/** 登录 */
export function login(data) {
  return http.post('/login', data)
}

/* 获取用户信息 */
export function getUserInfo() {
  return http.get('/getInfo')
}

// 添加获取 banner 数据的接口
export function getBannerData() {
  return http.get('/content/images/banner')
}

// 添加获取文章内容的接口
export function getArticleContent(id) {
  return httpGet(`/content/rich-text/${id}`)
}

//护工端登录
export function nurseLogin(data) {
  return http.post('/api/archive/login', {
    archiveCode: data.archiveCode,
    password: data.password
  })
}

// 获取客户订单列表（待确认）
export function getCustomerOrderList(data) {
  return http.post('/api/customer-orders/patient-contact/pending-settle', {
    patientContact: data.patientContact
  });
}

// 获取客户订单详情（全部）
export function getCustomerOrderDetail(data) {
  return http.post('/api/customer-orders/patient-contact', {
    patientContact: data.patientContact
  });
}


//订单评价 
export function orderrating(data) {
  // 添加接口层校验
  const payload = {
    punctualityRating: Number(data.punctualityRating) || 0,
    appearanceRating: Number(data.appearanceRating) || 0,
    attitudeRating: Number(data.attitudeRating) || 0,
    responsibilityRating: Number(data.responsibilityRating) || 0,
    professionalRating: Number(data.professionalRating) || 0,
    comment: String(data.comment || ''),
    orderId: Number(data.orderId),
    caregiverId: Number(data.caregiverId),
    dissatisfactionReason: String(data.dissatisfactionReason || ''),
    overallEvaluation: String(data.overallEvaluation || ''),
    improvementSuggestions: String(data.improvementSuggestions || '')
  }

  console.info('API请求载荷:', JSON.parse(JSON.stringify(payload)))

  return http.post('/api/order-ratings', payload, {
    validateStatus: (status) => status < 500
  })
}
//获取订单评价 
export function getOrderRating(data) {
  return httpGet('/api/order-ratings')
}

//客户订单状态更新（护工签到）
export function assignmentsign(data){
  return httpPut(`/api/customer-orders/${data.orderId}`,
    {
      status:"IN_SERVICE"
    }
  )
}
